// 统一的模型API适配器
import {
  getPythonModelList,
  getPythonModelVersionInfo,
  setPythonModelStatus,
  deletePythonModel,
  downloadPythonModel,
  PythonModelCalculate,
} from './manage'
import {
  getPMMLModelList,
  getVersionDetail,
  setPMMLModelStatus,
  deletePMMLModel,
  downloadPMMLModel,
  pmmlModelCalculate,
} from './pmml'
import {
  getScoreCardModelList,
  getScoreCardVersionDetail,
  setScoreCardModelStatus,
  deleteScoreCardModel,
  downloadScoreCardModel,
  scoreCardModelCalculate,
} from './scorecard'
// API映射配置
const API_CONFIG = {
  python: {
    getModelList: getPythonModelList,
    getModelVersionInfo: getPythonModelVersionInfo,
    setModelStatus: setPythonModelStatus,
    deleteModel: deletePythonModel,
    downloadModel: downloadPythonModel,
    // 模型测试
    modelCalculate: PythonModelCalculate,
  },
  pmml: {
    getModelList: getPMMLModelList,
    getModelVersionInfo: getVersionDetail,
    setModelStatus: setPMMLModelStatus,
    deleteModel: deletePMMLModel,
    downloadModel: downloadPMMLModel,
    // 模型测试
    modelCalculate: pmmlModelCalculate,
  },
  scorecard: {
    getModelList: getScoreCardModelList,
    getModelVersionInfo: getScoreCardVersionDetail,
    setModelStatus: setScoreCardModelStatus,
    deleteModel: deleteScoreCardModel,
    downloadModel: downloadScoreCardModel,
    // 模型测试
    modelCalculate: scoreCardModelCalculate,
  },
}

// 统一的API调用类
export class ModelAPIAdapter {
  constructor(modelType) {
    this.modelType = modelType
    this.config = API_CONFIG[modelType]

    if (!this.config) {
      throw new Error(`Unsupported model type: ${modelType}`)
    }
  }

  // 获取模型列表
  getModelList(params) {
    if (!this.config.getModelList) {
      throw new Error(`getModelList not implemented for ${this.modelType}`)
    }
    return this.config.getModelList(params)
  }

  // 获取模型版本信息
  getModelVersionInfo(params) {
    if (!this.config.getModelVersionInfo) {
      console.warn(`getModelVersionInfo not implemented for ${this.modelType}`)
      return { data: [] }
    }
    return this.config.getModelVersionInfo(params)
  }

  // 设置模型状态
  setModelStatus(params) {
    if (!this.config.setModelStatus) {
      throw new Error(`setModelStatus not implemented for ${this.modelType}`)
    }
    return this.config.setModelStatus(params)
  }

  // 删除模型
  deleteModel(params) {
    if (!this.config.deleteModel) {
      throw new Error(`deleteModel not implemented for ${this.modelType}`)
    }
    return this.config.deleteModel(params)
  }

  // 下载模型
  downloadModel(params, options) {
    if (!this.config.downloadModel) {
      throw new Error(`downloadModel not implemented for ${this.modelType}`)
    }
    return this.config.downloadModel(params, options)
  }

  // 生成PDF
  generatePDF(params, options) {
    if (!this.config.generatePDF) {
      throw new Error(`generatePDF not implemented for ${this.modelType}`)
    }
    return this.config.generatePDF(params, options)
  }

  // 模型测试
  modelCalculate(params) {
    if (!this.config.modelCalculate) {
      throw new Error(`modelCalculate not implemented for ${this.modelType}`)
    }
    return this.config.modelCalculate(params)
  }
}

// 工厂函数
export function createModelAPI(modelType) {
  return new ModelAPIAdapter(modelType)
}
